import javax.swing.plaf.basic.BasicToolBarSeparatorUI;
import java.util.Scanner;

/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.05.20
 *Time:18:34
 */
public class Main{

    //查找是否数组中存在连续的三个奇数返回ture or false
    public static boolean threeEven(int[] array){

        if(array.length < 3)
            return false;
        for (int i = 0;i < array.length - 2 ; i++){
            if(array[i] % 2 == 1 && array[i+1] %2 ==1 && array[i+2] %2 == 1)
               return true;
        }
        return false;
    }

    public static void main8(String[] args) {
        int[] array = {1,2,2,1,3,4,1,3,5};
        boolean r =threeEven(array);
        if(r == true)
            System.out.println("存在");
        else
            System.out.println("不存在");
    }
    //查找数组的单独存在的元素
    public static int searchSingleDog(int[] array){
        int tem = 0;
        for (int i = 0; i < array.length; i++) {
            tem ^= array[i];
        }
        return tem;
    }

    //查找多数元素：这一个数在数组中出现的次数多于n/2
    public static int mostElements(int[] array){
        int cnt = 1;
        for (int i = 0; i < (array.length) / 2 + 1; i++) {
            int j = i + 1;
            for (; j < array.length ; j++) {
                if(array[i] == array[j]){
                    cnt++;
                }
            }
            if(cnt > (array.length / 2))
                return 1;
        }
        return 0;
    }

    public static void main7(String[] args) {
        int[] arr = {0,2,3,1,1,1,1,1};
        int r = mostElements(arr);
        if(r == 1)
            System.out.println("存在");
        else
            System.out.println("不存在");
    }

    public static void main6(String[] args) {
        int[] array = {1,2,3,4,1,2,3,4,5};
        int r = searchSingleDog(array);
        System.out.println("array数组中单独存在的元素是：" + r );
    }

    //返回两个数的下标
    //法1：
    public static String reSum(int[] array,int target) {
        int len = array.length - 1;
        String ret = "[";
        for (int i = 0; i < array.length - 1; i++) {
            int j = i + 1;
            for (; j < array.length; j++) {
                if (array[i] + array[j] == target) {
                    ret += i;
                    ret += ",";
                    ret += j;
                    ret += "]";
                    return ret;
                }
            }
        }
        return null;
    }
    //法二
    public static int[] towSum(int[] array,int target){
        int[] result = new int[2];
        for (int i = 0; i < array.length -1; i++) {
            for (int j = array.length -1; j > i ; j--) {
                if(array[i] + array[j] == target) {
                    result[0] = i;
                    result[1] = j;
                }
            }
        }
        return result;
    }

    public static void main5(String[] args) {
        int[] arr = {1,2,3,4};
        int[] ret = towSum(arr,3);
        System.out.println();
    }

    //冒泡排序
    public  static  void bubbleSort(int[] array) {
        int len = array.length;
        for (int i = 0; i < len - 1; i++) {
            for (int j = 0; j < len - 1 - i; j++) {
                if (array[j] > array[j + 1]) {
                    int tem = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tem;
                }
            }
        }
    }


    public static void main4(String[] args) {
        int[] array = {3,5,7,2,9,10,1,4,6,8};
        bubbleSort(array);
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }

    }

    //二分查找
    public static int binarySearch(int[] array,int n){
        int left = 0;
        int right = array.length - 1;
        int mid = 0;
        while(left < right){
            mid =( left + right) / 2;
            if(array[mid] > n)
                right = mid - 1;
            if(array[mid] < n)
                left = mid + 1;
            if(array[mid] == n )
                return mid;
        }
            return -1;
    }

    public static void main3(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
       int r =  binarySearch(array,n);
       if(r != -1)
           System.out.println(n + "是数组中的数，下标为：" + r);
       else
           System.out.println(n + "不是该数组的元素");
    }

    //将数组中奇数放前，偶数放后
    public static void fun(int[] array){
        //定义左右下标
        int left = 0;
        int  right = array.length -1;
        while(left < right){
            while(array[left] %2 ==1)
                left++;
            while(array[right] %2 == 0)
                right --;
            //此时的left下标元素是偶数，right下标是奇数
            //交换
            int tem = array[left];
            array[left] = array[right];
            array[right] = tem;
        }
    }

    public static void main2(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        fun(array);
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
    }

    //传参数组，将数组元素*2
    public  static void double_Arr(int[] array){
        for(int i=0;i < array.length;i++){
            array[i] *= 2;
        }
    }

public static void main1(String[] args){
     int[] array = {1,2,3,4,5};
     double_Arr(array);
    for (int i = 0; i < array.length; i++) {
        System.out.print(array[i] + " ");
    }
}

}